<template>
  <div class="problem-wrap">

    <div class="problem-box" v-for="(item,index) in problemList" :key="index">
      <div class="title-box">
        <img :src="item.labelUrl" class="icon" onclick="return false"/>
        <span class="title">{{item.labelName}}</span>
      </div>
      <div class="problem-con">
        <div class="problem-list" v-for="(problem,index) in item.problemTitle.split('#')" :key="index"
             @click="openProblem(problem)">{{problem}}
        </div>
      </div>
    </div>

    <div class="mobile-box" @click="callPhone">
      <img src="./mobile.png" class="mobile" onclick="return false"/>
    </div>

    <div class="modal-wrap" v-show="rule">
      <div class="modal-box">
        <div class="modal-con">
          <div class="title-box">
            <span class="title">{{title}}</span>
            <img src="./close.png" class="del-icon" @click="close" onclick="return false"/>
          </div>
          <div class="rule-box" v-html="content"></div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  import {baseUrl} from "../../common/js/env";

  export default {
    data() {
      return {
        problem: "",
        phoneNum: "",
        problemList: [],
        rule: false,
        content: "",
        title: "",
        userSign: ""
      }
    },
    mounted() {
      let base64 = require('js-base64').Base64;
      this.userSign = base64.decode(sessionStorage.getItem("user_sign"));
      this.queryProblem();
    },
    methods: {
      queryProblem() {//查询问题列表
        this.$vux.loading.show({
          text: '加载中',
        });
        this.axios.get(baseUrl + "/customerser/query_problem?sgin=" + this.userSign).then((res) => {
          let resultObj = res.data;
          this.$vux.loading.hide();
          if (resultObj.code == 0 && resultObj.data != null) {
            this.phoneNum = resultObj.data.telephone;
            let list = resultObj.data.list;
            if (list != null && list.length > 0) {
              this.problemList = list;
            }
          } else {
            this.$vux.toast.text(resultObj.msg, "middle");
          }
        }).catch((error) => {
          this.$vux.loading.hide();
          this.$vux.toast.text("网络异常", "middle");
        });
      },
      callPhone() {//唤起拨号
        window.location.href = 'tel://' + this.phoneNum
      },
      openProblem(title) {//问题详情
        this.title = title;
        this.rule = true;
        this.axios.get(baseUrl + "/customerser/query_problem_detail?sgin=" + this.userSign + "&title=" + title).then((res) => {
          let resultObj = res.data;
          if (resultObj.code == 0 && resultObj.data != null) {
            if (resultObj.data.answer) {
              this.content = resultObj.data.answer.replace(/&lt;/g, "<").replace(/&gt;/g, ">");
            }
          } else {
            this.$vux.toast.text(resultObj.msg, "middle");
          }
        }).catch((error) => {
          this.$vux.toast.text("网络异常", "middle");
        });
      },
      close() {
        this.rule = false;
      }
    }
  }
</script>

<style lang="stylus" scoped>
  @import "../../common/stylus/mixin.styl"

  .problem-wrap
    position: fixed
    top: 0
    bottom: 0
    wh(100%, auto)
    background: rgba(242, 242, 242, 1)
    .problem-box
      display: flex
      align-items: center
      margin: 0 auto
      margin-top: 0.16rem
      margin-bottom: 0.16rem
      wh(94.4%, auto)
      background: rgba(255, 255, 255, 1)
      box-shadow: 0rem 0.013rem 0.107rem 0rem rgba(4, 4, 4, 0.16)
      border-radius(0.107rem)
      .title-box
        display: flex
        flex-direction: column
        align-items: center
        justify-content: center
        padding-top: 0.52rem
        padding-bottom: 0.52rem
        wh(20.48%, auto)
        .icon
          padding-bottom: 0.08rem
          wh(0.6rem, 0.693rem)
        .title
          padding-top: 0.08rem
          size-color(0.387rem, rgba(68, 68, 68, 1))

      .problem-con
        flex: 1
        margin-top: 0.2rem
        margin-bottom: 0.2rem
        .problem-list
          display: flex
          align-items: center
          padding-left: 0.28rem
          height: 1.12rem
          size-color(0.44rem, rgba(68, 68, 68, 1))
          border-left: 0.013rem solid rgba(230, 230, 230, 1)
          border-bottom: 0.013rem solid rgba(230, 230, 230, 1)
          &:last-child
            border-bottom: none
    .mobile-box
      position: fixed
      bottom: 1.787rem
      right: 0.427rem
      z-index: 99
      wh(1.04rem, 1.04rem)
      border-radius(50%)
      .mobile
        wh(100%, 100%)
    .modal-box
      position: fixed
      top: 0
      left: 0
      right: 0
      bottom: 0
      z-index: 100
      background-color: rgba(0, 0, 0, 0.5)
      .modal-con
        position: absolute
        width: 100%
        height: 10.04rem
        bottom: 0
        background: #FFF
        .title-box
          display: flex
          align-items: center
          width: 100%
          height: 1.333rem
          border-bottom: 0.013rem solid rgba(204, 204, 204, 1)
          .title
            display: flex
            justify-content: center
            width: 100%
            size-color(0.44rem, rgba(27, 27, 27, 1))
            font-weight: 500
          .del-icon
            position: absolute
            wh(0.387rem, 0.387rem)
            right: 0.373333rem
        .rule-box
          width: 92.53%
          height: auto
          margin: 0 auto
          margin-top: 0.373333rem
          font-size: 0.413333rem
          color: rgba(68, 68, 68, 1)
          line-height: 0.626666rem
          margin-bottom: 0.52rem

</style>
